import fs from 'fs-extra';

export class Relatives {
    private _isUsed = false;
    private _relatedGuids: string[] = [];

    public beginUse(): void {
        this._isUsed = true;
        this._relatedGuids.length = 0;
    }

    public stopUse(): void {
        this._isUsed = false;
    }

    public async collect(file: string): Promise<void> {
        const content = await fs.readFile(file, 'utf-8');
        const guids = content.matchAll(/guid: (\w{32})/g);
        for (const g of guids) {
            this._relatedGuids.push(g[1]);
        }
    }

    public get isUsed(): boolean {
        return this._isUsed;
    }

    public isRelated(guid: string): boolean {
        return this._relatedGuids.includes(guid);
    }
}